package com.hzhq.contract.convert;

import com.hzhq.contract.bean.dto.ContractTemplateDTO;
import com.hzhq.contract.bean.entity.ContractTemplate;
import com.hzhq.contract.bean.vo.ContractTemplateVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

/**
 * @author hzhq
 * @create 2021/4/12 5:30 下午
 * @email hzhq1255@163.com
 */
@Mapper
public interface ContractTemplateConvertBasic {

    ContractTemplateConvertBasic INSTANCE = Mappers.getMapper(ContractTemplateConvertBasic.class);


    ContractTemplateDTO poToDto(ContractTemplate template);


    ContractTemplate dtoToPo(ContractTemplateDTO source);


    @Mappings({
            @Mapping(target = "templateId", expression = "java(com.hzhq.contract.util.ConvertUtil.objectIdToString(source.getTemplateId()))"),
            @Mapping(target = "companiesA", expression = "java(com.hzhq.contract.convert.method.ContractTemplateConvertMethod.companiesToString(source.getCompaniesA()))"),
            @Mapping(target = "companiesB", expression = "java(com.hzhq.contract.convert.method.ContractTemplateConvertMethod.companiesToString(source.getCompaniesB()))"),
            @Mapping(target = "contractType", expression = "java( null != source.getContractType().getTypeName() ? source.getContractType().getTypeName() : null)"),
            @Mapping(target = "createUser", expression = "java( null != source.getCreateUser().getUsername() ? source.getCreateUser().getUsername() : null)"),
            @Mapping(target = "depart", expression = "java(null != source.getDepart().getDepartName() ? source.getDepart().getDepartName() : null)")
    })
    ContractTemplateVO dtoToVo(ContractTemplateDTO source);

//    @Mappings({
//            @Mapping(target = "templateId", expression = "java(com.hzhq.contract.util.ConvertUtil.stringToObjectId(source.getTemplateId()))"),
//            @Mapping(target = "companiesA", expression = "java(com.hzhq.contract.convert.method.ContractTemplateConvertMethod.voList2entityList(source.getCompaniesA()))"),
//            @Mapping(target = "companiesB", expression = "java(com.hzhq.contract.convert.method.ContractTemplateConvertMethod.voList2entityList(source.getCompaniesB()))"),
//            @Mapping(target = "contractType", expression = "java(com.hzhq.contract.convert.method.ContractTemplateConvertMethod.string2ContractType(source.getContractType()))"),
//            @Mapping(target = "createUser", expression = "java(com.hzhq.contract.convert.method.ContractTemplateConvertMethod.string2User(source.getCreateUser()))"),
//            @Mapping(target = "depart", expression = "java(com.hzhq.contract.convert.method.ContractTemplateConvertMethod.string2Depart(source.getDepart()))")
//    })
//    ContractTemplateDTO voToDto(ContractTemplateVO source);
}
